package common;

import java.awt.Component;

import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTable;
import javax.swing.table.DefaultTableCellRenderer;

/**
 * This class is a Custom TableCellRendere used to show an icon instead "true" or "false".
 * @author marko
 *
 */
public class ImageCellRenderer extends DefaultTableCellRenderer {

	Icon trueIcon = new ImageIcon(getClass().getClassLoader().getResource("images/icons/active16.png"));
	Icon falseIcon = new ImageIcon(getClass().getClassLoader().getResource("images/icons/deactive16.png"));
	
	@Override
	public Component getTableCellRendererComponent(JTable table, Object value,
			boolean isSelected, boolean hasFocus, int row, int column) {
		
		JLabel label = (JLabel)super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);

		System.out.println(value);
		if (value.toString().equals("true"))
		{
			label.setIcon(trueIcon);
			label.setText(null);
		}
		else
		{
			label.setIcon(falseIcon);
			label.setText(null);
		}
		setHorizontalAlignment(CENTER);
		return super.getTableCellRendererComponent(table, null, isSelected, hasFocus, row, column);
	}
	
	

}
